class xT_PlayerCamera_OrbitCamera extends GameCameraBase;

var int MinCameraDegrees;
var int MaxCameraDegrees;

var float Distance;
var float MinDistance;
var float MaxDistance;
var float ZoomStep;

/** Expected to fill in OutVT with new camera pos/loc/fov. */
function UpdateCamera(Pawn P, GamePlayerCamera aCameraActor, float aDeltaTime, out TViewTarget OutVT)
{
	local vector    cameraOffset;
	local Rotator   camRotation;

	super.UpdateCamera(P, aCameraActor, aDeltaTime, OutVT);

 	//limit pitch in conroller rotation
 	camRotation = LimitViewRotation(OutVT.Target.Rotation, (90 - MaxCameraDegrees) * 182, (90 - MinCameraDegrees) * 182);
 
 	//calculate cam offset
 	cameraOffset = Vector(camRotation) * -Distance;
 
 	OutVT.POV.FOV = 80.0f;
 	OutVT.POV.Location = OutVT.Target.Location + cameraOffset;
 	OutVT.POV.Rotation = camRotation;
}

function ProcessViewRotation( float DeltaTime, Actor ViewTarget, out Rotator out_ViewRotation, out Rotator out_DeltaRot )
{
	super.ProcessViewRotation(DeltaTime, ViewTarget, out_ViewRotation, out_DeltaRot);

	out_ViewRotation += out_DeltaRot;
	out_ViewRotation = LimitViewRotation(out_ViewRotation, ((90 - MaxCameraDegrees)* DegToRad) * RadToUnrRot, 
		((90 - MinCameraDegrees)* DegToRad) * RadToUnrRot);
}

function Rotator LimitViewRotation( Rotator ViewRotation, float ViewPitchMin, float ViewPitchMax )
{
	ViewRotation.Pitch = Clamp(ViewRotation.Pitch, 49152 + ViewPitchMin, 49152 + ViewPitchMax);

	return ViewRotation;
}

function Init()
{
	super.Init();
}

function ZoomIn()
{
	Distance -= ZoomStep;
	Distance = Clamp(Distance, MinDistance, MaxDistance);
}

function ZoomOut()
{
	Distance += ZoomStep;
	Distance = Clamp(Distance, MinDistance, MaxDistance);
}

//=============================================================================
// Default Properties
//=============================================================================
defaultproperties
{
	MinCameraDegrees=35
	MaxCameraDegrees=75

	Distance=1024.0f
	MinDistance=256.0f
	MaxDistance=768.0f
	ZoomStep=128.0f
}